﻿package tagul {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.ui.*;

    public class EventBox extends Sprite {
        private var _tag:Tag;

        public function EventBox(tag:Tag, popup:Boolean = false):void {
            this._tag = tag;
            graphics.beginFill(0, 0);
            graphics.drawRect(this._tag.bbox.x, this._tag.bbox.y, this._tag.bbox.width, this._tag.bbox.height);
            graphics.endFill();
            transform.matrix = this._tag.transform.matrix;
            buttonMode = true;
            
            addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void {
                    var _loc_2:String = null;
                    if (popup && !(event.shiftKey || event.ctrlKey)) {
                        _loc_2 = "javascript:window.opener.window.location.href=\"" + _tag.url + "\"; window.close(); void(0);";
                        navigateToURL(new URLRequest(_loc_2), "_self");
                    } else {
                        _tag.openURL(event.shiftKey || event.ctrlKey ? ("_blank") : ("_blank"));
                    }
                    return;
                } // end function
                );
            addEventListener(MouseEvent.ROLL_OVER, function(event:MouseEvent):void {
                    _tag.startAnimation();
                    return;
                } // end function
                );
            addEventListener(MouseEvent.ROLL_OUT, function(event:MouseEvent):void {
                    _tag.stopAnimation();
                    return;
                } // end function
                );
            return;
        } // end function

    }
}
